<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        // function fn (msg, t) {
        //     return new Promise((resolve, reject) => {
        //         setTimeout(() => {
        //             resolve(msg);
        //         }, t);
        //     });
        // }

        // async function f1 () {
        //     const res = await fn('hello world', 1000);
        //     console.log(res);
        //     const res1 = await fn('hi', 2000);
        //     console.log(res1);
        // }

        // f1();

        const url = 'http://www.liulongbin.top:3006/api/news'; // url + '?name=zhangsan&age=18'

        function axios (conf) {
            return new Promise((resolve, reject) => {
                // 1.
                const xhr = new XMLHttpRequest();
                // 2.
                xhr.open(conf.method, conf.url);
                // 3.
                xhr.send();
                // 4.
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4 && xhr.status === 200) {
                        resolve(JSON.parse(xhr.responseText));
                    }
                };
            });
        }

        (async () => {

            console.log('开启loading');
            const res = await axios({
                method: 'get',
                url,
            });

            // console.log(res);
            const res1 = await axios({
                method: 'get',
                url,
            });
            // console.log(res1);
            const res2 = await axios({
                method: 'get',
                url,
            });
            console.log('结束loading');
            // console.log(res2);


        })();

    </script>
</body>
</html>